   

import os
import sys
proj_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(proj_path)
from openai import OpenAI







class ModelClient:
    client = None
    def __init__(self):
        if hasattr(self, 'initialized'):
            return
        self.initialized = True
        self.vllm_server_url ="http://10.118.21.198:21082"
        self.api_key = "EMPTY"
        self.model_name ="Qwen2.5-VL-32B"
        if not self.vllm_server_url or not self.api_key or not self.model_name:
            raise Exception("vl_openai_server or vl_openai_api_key or vl_openai_model_name is empty")
        self.client = OpenAI(
            api_key=self.api_key,
            base_url=f'{self.vllm_server_url}/v1'
        )
        self.prompt = """你是一个专业的图片分类器，只需判断图片是否属于以下两类：

集装箱 - 输出：集装箱：TRUE
报关单 - 输出：报关单：TRUE

若图片不属于以上两类，则输出：
集装箱：FALSE
报关单：FALSE

要求：

仅输出上述指定格式的判定结果

不要添加任何解释或额外内容

确保每个类目都有TRUE/FALSE的判断
        """


model_client = ModelClient()


def model_execute(image_path:str):
        
        response = model_client.client.chat.completions.create(
            model=model_client.model_name,
            messages=[
                {
                    "role": "system",
                    "content": model_client.prompt
                },
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "image_url",
                            "image_url": {"url": image_path}
                        }
                    ]
                }
            ]
        )
        return response.choices[0].message.content


if __name__ == '__main__':
     
    img_list=["http://10.118.21.239:89/test/test/czj/集装箱1.png",
              "http://10.118.21.239:89/test/test/czj/集装箱2.png",
              "http://10.118.21.239:89/test/test/czj/报关单1.png",
              "http://10.118.21.239:89/test/test/czj/报关单2.png",
              "http://10.118.21.239:89/test/test/czj/人脸.png",
              "http://10.118.21.239:89/test/test/czj/办公室.png",
              "http://10.118.21.239:89/test/test/czj/网址.png",
              "http://10.118.21.239:89/test/test/czj/熊猫.png"]

    for img_path in img_list:
       classfy=model_execute(img_path)
       print(f"*****当前图片{img_path}****，\n ****当前分类**** {classfy}")